
import requests
from bs4 import BeautifulSoup

url = "https://so.gushiwen.cn/shiwenv_45c396367f59.aspx"
req = requests.get(url)
if req.status_code == 200:
    soup = BeautifulSoup(req.text, 'html.parser')
    with open(f'{soup.h1.get_text()}.txt', 'w', encoding='utf-8') as file:
        file.write(soup.h1.get_text())
        file.write("\n")
        file.write(soup.find('p', 'source').get_text())
        file.write("\n")
        poems = soup.find('div', 'contson').get_text("|").split("|")
        for i in poems:
            file.write(i.strip())
            file.write("\n")
